import Packet from "../net/Packet"

// 账号登录
export default class AccountLogin {
	/**
	 * @param account 账号
	 * @param time 登录时间
	 * @param sign 校验码
	 */
	public constructor(public account: string, public time: number, public sign: string) { }

	public encode(): Packet {
		const packet = this._encode()
		packet.Encode(2010)
		return packet
	}

	public encodeMsg(): ByteBuffer {
		return this._encode().GetBuffer()
	}

	public static decode(packet: Packet): AccountLogin {
		const account = packet.ReadString()
		const time = packet.ReadUint()
		const sign = packet.ReadString()
		return new AccountLogin(account, time, sign)
	}

	private _encode(): Packet {
		const packet = new Packet()
		packet.WriteString(this.account)
		packet.WriteUint(this.time)
		packet.WriteString(this.sign)
		return packet
	}
}
